/*
 * Powered By 
 * Since 2010 - 2016
 */

package com.rf.business.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.rf.sys.dao.SqlAdapterMapper;
import com.rf.sys.utils.PageUtils;
import com.rf.sys.utils.StringUtils;
import com.rf.business.model.CardRelease;
import com.rf.business.service.CardReleaseSearchService;

@Service("cardReleaseSearchService")
public class CardReleaseSearchServiceImpl implements CardReleaseSearchService {

	@Autowired
   	private SqlAdapterMapper sqlAdapterMapper;//注入dao
	
	@Override
	public Map getCardReleasePage(CardRelease cardRelease, PageUtils pageUtils)throws Exception {
		//下一条执行语句，即为要被转换的语句
		StringBuffer sql =new StringBuffer("SELECT   E.* FROM  BUS_CARD_RELEASE E WHERE 1=1");
		//车牌号过滤
		if(StringUtils.isNotBlank(cardRelease.getCarNo())){
			sql.append(" AND E.CAR_NO like '%"+cardRelease.getCarNo()+"%'");
		}
		//出入境类型
		if(StringUtils.isNotBlank(cardRelease.getEntryExitType())){
			sql.append(" AND E.ENTRY_EXIT_TYPE = '"+cardRelease.getEntryExitType()+"'");
		}
		sql.append(" order by E.ENTRY_TIME desc");
		//获取第offset页，每页共limit条内容，默认查询总数count
		Page p = PageHelper.startPage(pageUtils.getPage(), pageUtils.getRows());
		List<Map<String, Object>> list=sqlAdapterMapper.selectSQL(sql.toString());
		Map dateMap = new HashMap();
	    dateMap.put("total", p.getTotal());
	    dateMap.put("rows", list);
		return dateMap;
	}

	/**
	 * 综合统计
	 */
	@Override
	public Map getSumPage(CardRelease cardRelease, PageUtils pageUtils,String startdate, String enddate) throws Exception {
		
		String carNoCondition="";
		String nationalityCondition="";
		String entryExitTypeCondition="";
		String carTypeCondition="";
		String startdateCondition1="";
		String startdateCondition2="";
		String enddateCondition1="";
		String enddateCondition2="";
		//车牌号过滤
		if(StringUtils.isNotBlank(cardRelease.getCarNo())){
			carNoCondition=" and CAR_NO="+cardRelease.getCarNo();
		}
		//国籍
		if(StringUtils.isNotBlank(cardRelease.getNationality())){
			nationalityCondition=" and NATIONALITY="+cardRelease.getNationality();
		}
		//出入境类型
		if(StringUtils.isNotBlank(cardRelease.getEntryExitType())){
			entryExitTypeCondition=" and ENTRY_EXIT_TYPE="+cardRelease.getEntryExitType();
		}
		//车辆类型
		if(StringUtils.isNotBlank(cardRelease.getCarType())){
			carTypeCondition=" and CAR_TYPE="+cardRelease.getCarType();
		}
		//	起始时间
		if(StringUtils.isNotBlank(startdate)){
			startdateCondition1=" and ENTRY_TIME>=TO_DATE('"+startdate+"','yyyy-MM-dd')";
//			startdateCondition1=" AND GATE_CHECK_DATE>=TO_DATE('"+startdate+"','yyyy-MM-dd')";
//			startdateCondition2=" AND FINAL_CHECK_DATe>=TO_DATE('"+startdate+"','yyyy-MM-dd')";
		}
		//	结束时间
		if(StringUtils.isNotBlank(enddate)){
			enddateCondition1=" and ENTRY_TIME<=TO_DATE('"+enddate+"','yyyy-MM-dd')+1";
//			enddateCondition1=" AND GATE_CHECK_DATE<=TO_DATE('"+enddate+"','yyyy-MM-dd')";
//			enddateCondition2=" AND FINAL_CHECK_DATe<=TO_DATE('"+enddate+"','yyyy-MM-dd')";
		}
		String Condition=carNoCondition+nationalityCondition+entryExitTypeCondition+carTypeCondition+startdateCondition1+enddateCondition1;
		//下一条执行语句，即为要被转换的语句
		StringBuffer sql =new StringBuffer("select (select sum(1) from BUS_CARD_RELEASE t where t.entry_exit_type='101101' and t.GATE_CHECK_STATE='101402'  and NATIONALITY = '100501' "+Condition+") inecar,(select sum(1) from BUS_CARD_RELEASE t where t.entry_exit_type='101101' and t.GATE_CHECK_STATE='101402'  and NATIONALITY not in ('100501','100503') "+Condition+") inothercar,(select sum(1) from BUS_CARD_RELEASE t where t.entry_exit_type='101101' and t.GATE_CHECK_STATE='101402'  and NATIONALITY not in ('100503') "+Condition+") inothercarsum,(select sum(1) from BUS_CARD_RELEASE t where t.entry_exit_type='101101' and t.GATE_CHECK_STATE='101402'  and NATIONALITY  in ('100503') "+Condition+") inchinacar,(select sum(1) from BUS_CARD_RELEASE t where t.entry_exit_type='101101' and t.GATE_CHECK_STATE='101402' "+Condition+") incarcount,"
				+ "(select sum(1) from BUS_CARD_RELEASE t where t.entry_exit_type='101102' and t.FINAL_CHECK_STATE='101402'  and NATIONALITY = '100501' "+Condition+") outecar,(select sum(1) from BUS_CARD_RELEASE t where t.entry_exit_type='101102' and t.FINAL_CHECK_STATE='101402'  and NATIONALITY not in ('100501','100503') "+Condition+") outothercar,(select sum(1) from BUS_CARD_RELEASE t where t.entry_exit_type='101102' and t.FINAL_CHECK_STATE='101402'  and NATIONALITY not in ('100503') "+Condition+") outothercarsum,(select sum(1) from BUS_CARD_RELEASE t where t.entry_exit_type='101102' and t.FINAL_CHECK_STATE='101402'  and NATIONALITY  in ('100503') "+Condition+") outchinacar,(select sum(1) from BUS_CARD_RELEASE t where t.entry_exit_type='101102' and t.FINAL_CHECK_STATE='101402' "+Condition+") outcarcount,"
				+ "(select sum(t.total_num) from BUS_CARD_RELEASE t where t.entry_exit_type='101101' and t.FINAL_CHECK_STATE='101402' "+Condition+") inpercount,(select sum(t.CHINESE_NUM) from BUS_CARD_RELEASE t where t.entry_exit_type='101101' and t.FINAL_CHECK_STATE='101402' "+Condition+") inchinapercount,(select sum(t.FOREIGN_NUM) from BUS_CARD_RELEASE t where t.entry_exit_type='101101' and t.FINAL_CHECK_STATE='101402' "+Condition+") inotherpercount,"
				+ "(select sum(t.total_num) from BUS_CARD_RELEASE t where t.entry_exit_type='101102' and t.FINAL_CHECK_STATE='101402' "+Condition+") outpercount,(select sum(t.CHINESE_NUM) from BUS_CARD_RELEASE t where t.entry_exit_type='101102' and t.FINAL_CHECK_STATE='101402' "+Condition+") outchainapercount,(select sum(t.FOREIGN_NUM) from BUS_CARD_RELEASE t where t.entry_exit_type='101102' and t.FINAL_CHECK_STATE='101402' "+Condition+") outotherpercount from dual");
		//获取第offset页，每页共limit条内容，默认查询总数count
		Page p = PageHelper.startPage(pageUtils.getPage(), pageUtils.getRows());
		List<Map<String, Object>> list=sqlAdapterMapper.selectSQL(sql.toString());
		Map dateMap = new HashMap();
	    dateMap.put("total", p.getTotal());
	    dateMap.put("rows", list);
		return dateMap;
	}

	/**
	 * 出入境时间统计
	 */
	@Override
	public Map getSumTimePage(CardRelease cardRelease, PageUtils pageUtils,String startdate, String enddate) throws Exception {
		StringBuffer sql =new StringBuffer();
		//出入境类型
		if(StringUtils.isNotBlank(cardRelease.getEntryExitType())){
			if(cardRelease.getEntryExitType().equals("101101")){
				sql.append("select e.*,round((e.NATION_CHECK_DATE-e.entry_time)*24*60,0) gjsum,round((e.BORDER_CHECK_DATE-e.entry_time)*24*60,0) bjsum,round((e.PORT_CHECK_DATE-e.entry_time)*24*60,0) kasum,round((e.CUSTOM_CHECK_DATE-e.entry_time)*24*60,0) hgsum,round((e.MEET_CAR_DATE-e.entry_time)*24*60,0) zlssum,round((e.GATE_CHECK_DATE-e.entry_time)*24*60,0) nkksum,round((e.OPE_CHECK_DATE-e.entry_time)*24*60,0) tdsum from BUS_CARD_RELEASE e where 1=1");
			}else{
				sql.append("select e.*,0 ybdsum,round((e.NATION_CHECK_DATE-e.entry_time)*24*60,0) gjsum,round((e.BORDER_CHECK_DATE-e.entry_time)*24*60,0) bjsum,round((e.PORT_CHECK_DATE-e.entry_time)*24*60,0) kasum,round((e.CUSTOM_CHECK_DATE-e.entry_time)*24*60,0) hgsum,round((e.MEET_CAR_DATE-e.entry_time)*24*60,0) zlssum,round((e.GATE_CHECK_DATE-e.entry_time)*24*60,0) nkksum,round((e.OPE_CHECK_DATE-e.entry_time)*24*60,0) ygsum,round((e.final_check_date - e.entry_time) * 24 * 60, 0) zjtsum from BUS_CARD_RELEASE e WHERE 1=1");
			}
			sql.append(" AND ENTRY_EXIT_TYPE = '"+cardRelease.getEntryExitType()+"'");
		}
		//车牌号过滤
		if(StringUtils.isNotBlank(cardRelease.getCarNo())){
			sql.append(" AND CAR_NO like '%"+cardRelease.getCarNo()+"%'");
		}
		//南卡口状态
		if(StringUtils.isNotBlank(cardRelease.getGateCheckState())){
			sql.append(" AND GATE_CHECK_STATE = '"+cardRelease.getGateCheckState()+"'");
		}
		//终检亭状态
		if(StringUtils.isNotBlank(cardRelease.getFinalCheckState())){
			sql.append(" AND FINAL_CHECK_STATE = '"+cardRelease.getFinalCheckState()+"'");
		}
		//起始日期
		if(StringUtils.isNotBlank(startdate)){
			sql.append(" and ENTRY_TIME>=TO_DATE('"+startdate+"','yyyy-MM-dd')");
		}
		//截止日期
		if(StringUtils.isNotBlank(enddate)){
			sql.append(" and ENTRY_TIME<=TO_DATE('"+enddate+"','yyyy-MM-dd')+1");
		}
		//获取第offset页，每页共limit条内容，默认查询总数count
		Page p = PageHelper.startPage(pageUtils.getPage(), pageUtils.getRows());
		List<Map<String, Object>> list=sqlAdapterMapper.selectSQL(sql.toString());
		Map dateMap = new HashMap();
	    dateMap.put("total", p.getTotal());
	    dateMap.put("rows", list);
		return dateMap;
	}
	
	//口岸物业验放统计
	public Map getkawysum(CardRelease cardRelease,PageUtils pageUtils,String startdate,String enddate) throws Exception{
		String sdate="";
		String carno="";
		if(startdate!=null&&!startdate.equals("")){
			sdate=sdate+" and port_check_date>=to_date('"+startdate+"','yyyy-MM-dd')";
		}
		if(enddate!=null&&!enddate.equals("")){
			sdate=sdate+" and port_check_date<=to_date('"+enddate+"','yyyy-MM-dd')+1";
		}
		if(cardRelease.getCarNo()!=null&&!cardRelease.getCarNo().equals("")){
			carno=" and username like '%"+cardRelease.getCarNo()+"%'";
		}
		StringBuffer sql =new StringBuffer("select * from (select (select r.user_name from sys_user r where r.id=port_check_user) username,o.*  from (select e.port_check_user,e.port_check_date,count(*) scount from BUS_CARD_RELEASE e  group by e.port_check_user,e.port_check_date having port_check_user is not null) o order by port_check_date,username) where 1=1 "+carno+sdate);
		//获取第offset页，每页共limit条内容，默认查询总数count
		Page p = PageHelper.startPage(pageUtils.getPage(), pageUtils.getRows());
		List<Map<String, Object>> list=sqlAdapterMapper.selectSQL(sql.toString());
		Map dateMap = new HashMap();
	    dateMap.put("total", p.getTotal());
	    dateMap.put("rows", list);
		return dateMap;
	}
	//口岸物业验放明细
	public Map getkawymx(CardRelease cardRelease,PageUtils pageUtils,String startdate,String enddate) throws Exception{
		String sdate="";
		String carno="";
		String nationality="";
		String entry_exit_type="";
		String car_type="";
		if(startdate!=null&&!startdate.equals("")){
			sdate=sdate+" and entry_time>=to_date('"+startdate+"','yyyy-MM-dd')";
		}
		if(enddate!=null&&!enddate.equals("")){
			sdate=sdate+" and entry_time<=to_date('"+enddate+"','yyyy-MM-dd')+1";
		}
		if(cardRelease.getCarNo()!=null&&!cardRelease.getCarNo().equals("")){
			carno=" and car_no like '%"+cardRelease.getCarNo()+"%'";
		}
		if(cardRelease.getNationality()!=null&&!cardRelease.getNationality().equals("")){
			nationality=" and nationality ='"+cardRelease.getNationality()+"'";
		}
		if(cardRelease.getEntryExitType()!=null&&!cardRelease.getEntryExitType().equals("")){
			entry_exit_type=" and username like '%"+cardRelease.getEntryExitType()+"%'";
		}
		if(cardRelease.getCarType()!=null&&!cardRelease.getCarType().equals("")){
			car_type=" and car_type='"+cardRelease.getCarType()+"'";
		}
		StringBuffer sql =new StringBuffer("select * from (select (select r.user_name from sys_user r where r.id=e.port_check_user) username,to_char(e.port_check_date,'yyyy-MM-dd hh:mm:ss') portcheckdate,(select y.data_name from sys_dictionary y where y.data_code=e.car_type and y.class_code='1009') cartypename,(select y.data_name from sys_dictionary y where y.data_code=e.nationality and y.class_code='1005') nationname,e.* from BUS_CARD_RELEASE e ) where 1=1"+carno+sdate+nationality+entry_exit_type+car_type);
		//获取第offset页，每页共limit条内容，默认查询总数count
		Page p = PageHelper.startPage(pageUtils.getPage(), pageUtils.getRows());
		List<Map<String, Object>> list=sqlAdapterMapper.selectSQL(sql.toString());
		Map dateMap = new HashMap();
	    dateMap.put("total", p.getTotal());
	    dateMap.put("rows", list);
		return dateMap;
	}
	//旅行社接车统计
	public Map getlxsjc(CardRelease cardRelease,PageUtils pageUtils,String startdate,String enddate) throws Exception{
		String sdate="";
		String carno="";
		String meetorg="";
		if(startdate!=null&&!startdate.equals("")){
			sdate=sdate+" and entry_time>=to_date('"+startdate+"','yyyy-MM-dd')";
		}
		if(enddate!=null&&!enddate.equals("")){
			sdate=sdate+" and entry_time<=to_date('"+enddate+"','yyyy-MM-dd')+1";
		}
		if(cardRelease.getCarNo()!=null&&!cardRelease.getCarNo().equals("")){
			carno=" and e.car_no like '%"+cardRelease.getCarNo()+"%'";
		}
		if(cardRelease.getMeetCarUser()!=null&&!cardRelease.getMeetCarUser().equals("")){
			meetorg=" and e.meet_car_user in (select r.user_id from bus_dep_user r where r.dep_id='"+cardRelease.getMeetCarUser()+"')";
		}
		StringBuffer sql =new StringBuffer("select q.*,ceil(q.outtime-q.intime) days  from (select orgname,car_no,max(intime) intime,max(outtime) outtime,count(*) countsum from (　select (select t.name from Bus_Department t,Bus_Dep_User r where t.id=r.dep_id and r.user_id=e.MEET_CAR_USER) orgname,e.CAR_NO,decode(entry_exit_type,'101102',entry_time,null) outtime,decode(entry_exit_type,'101101',entry_time,null) intime from BUS_CARD_RELEASE  e where e.meet_car_user is not null "+carno+meetorg+sdate+" order by orgname,car_no)  group by orgname,car_no) q");
		
		//获取第offset页，每页共limit条内容，默认查询总数count
		Page p = PageHelper.startPage(pageUtils.getPage(), pageUtils.getRows());
		List<Map<String, Object>> list=sqlAdapterMapper.selectSQL(sql.toString());
		Map dateMap = new HashMap();
	    dateMap.put("total", p.getTotal());
	    dateMap.put("rows", list);
		return dateMap;
	}
	//车辆类型统计
	public Map getcartypesum(CardRelease cardRelease,PageUtils pageUtils,String startdate,String enddate) throws Exception{
		String sdate="";
		String carno="";
		String nationality="";
		String entry_exit_type="";
		String car_type="";
		if(startdate!=null&&!startdate.equals("")){
			sdate=sdate+" and entry_time>=to_date('"+startdate+"','yyyy-MM-dd')";
		}
		if(enddate!=null&&!enddate.equals("")){
			sdate=sdate+" and entry_time<=to_date('"+enddate+"','yyyy-MM-dd')+1";
		}
		if(cardRelease.getCarNo()!=null&&!cardRelease.getCarNo().equals("")){
			carno=" and car_no like '%"+cardRelease.getCarNo()+"%'";
		}
		if(cardRelease.getNationality()!=null&&!cardRelease.getNationality().equals("")){
			nationality=" and nationality ='"+cardRelease.getNationality()+"'";
		}
		if(cardRelease.getEntryExitType()!=null&&!cardRelease.getEntryExitType().equals("")){
			entry_exit_type=" and entry_exit_type='"+cardRelease.getEntryExitType()+"'";
		}
		if(cardRelease.getCarType()!=null&&!cardRelease.getCarType().equals("")){
			car_type=" and car_type='"+cardRelease.getCarType()+"'";
		}
		StringBuffer sql =new StringBuffer("select w.*,(select y.data_name from sys_dictionary y where y.data_code=w.car_type) data_name from (select e.car_type,sum(outtimes) outtimes,sum(intimes) intimes from (select car_type,decode(entry_exit_type,'101102',1,null) outtimes,decode(entry_exit_type,'101101',1,null) intimes from BUS_CARD_RELEASE where 1=1 "+carno+sdate+nationality+entry_exit_type+car_type+") e group by e.car_type ) w");
		//获取第offset页，每页共limit条内容，默认查询总数count
		Page p = PageHelper.startPage(pageUtils.getPage(), pageUtils.getRows());
		List<Map<String, Object>> list=sqlAdapterMapper.selectSQL(sql.toString());
		Map dateMap = new HashMap();
	    dateMap.put("total", p.getTotal());
	    dateMap.put("rows", list);
		return dateMap;
	}
	//车辆进出境统计
	public Map getinoutsum(CardRelease cardRelease,PageUtils pageUtils,String startdate,String enddate) throws Exception{
		String sdate="";
		String carno="";
		String nationality="";
		String entry_exit_type="";
		String car_type="";
		if(startdate!=null&&!startdate.equals("")){
			sdate=sdate+" and entry_time>=to_date('"+startdate+"','yyyy-MM-dd')";
		}
		if(enddate!=null&&!enddate.equals("")){
			sdate=sdate+" and entry_time<=to_date('"+enddate+"','yyyy-MM-dd')+1";
		}
		if(cardRelease.getCarNo()!=null&&!cardRelease.getCarNo().equals("")){
			carno=" and car_no like '%"+cardRelease.getCarNo()+"%'";
		}
		if(cardRelease.getNationality()!=null&&!cardRelease.getNationality().equals("")){
			nationality=" and nationality ='"+cardRelease.getNationality()+"'";
		}
		if(cardRelease.getEntryExitType()!=null&&!cardRelease.getEntryExitType().equals("")){
			entry_exit_type=" and entry_exit_type='"+cardRelease.getEntryExitType()+"'";
		}
		if(cardRelease.getCarType()!=null&&!cardRelease.getCarType().equals("")){
			car_type=" and car_type='"+cardRelease.getCarType()+"'";
		}
		StringBuffer sql =new StringBuffer("select  car_no,car_type,(select y.data_name from sys_dictionary y where y.data_code=car_type) data_name,sum(outtimes) outtimes,sum(intimes) intimes,sum(intimes) outchina,sum(intimes) inchina,sum(outfor) outfor,sum(infor) infor from (select e.car_no,e.car_type,decode(entry_exit_type,'101102',1,null) outtimes,decode(entry_exit_type,'101101',1,null) intimes,decode(entry_exit_type,'101102',e.chinese_num,null) outchina,decode(entry_exit_type,'101101',e.chinese_num,null) inchina,decode(entry_exit_type,'101102',e.foreign_num,null) outfor,decode(entry_exit_type,'101101',e.foreign_num,null) infor from BUS_CARD_RELEASE e where 1=1 "+carno+sdate+nationality+entry_exit_type+car_type+") group by car_no,car_type");
		//获取第offset页，每页共limit条内容，默认查询总数count
		Page p = PageHelper.startPage(pageUtils.getPage(), pageUtils.getRows());
		List<Map<String, Object>> list=sqlAdapterMapper.selectSQL(sql.toString());
		Map dateMap = new HashMap();
	    dateMap.put("total", p.getTotal());
	    dateMap.put("rows", list);
		return dateMap;
	}
	//入境未出区统计
	public Map getinsum(CardRelease cardRelease,PageUtils pageUtils,String startdate,String enddate) throws Exception{
		String sdate="";
		String carno="";
		if(startdate!=null&&!startdate.equals("")){
			sdate=sdate+" and entry_time>=to_date('"+startdate+"','yyyy-MM-dd')";
		}
		if(enddate!=null&&!enddate.equals("")){
			sdate=sdate+" and entry_time<=to_date('"+enddate+"','yyyy-MM-dd')+1";
		}
		if(cardRelease.getCarNo()!=null&&!cardRelease.getCarNo().equals("")){
			carno=" and car_no like '%"+cardRelease.getCarNo()+"%'";
		}
		StringBuffer sql =new StringBuffer("select e.car_no,e.entry_time,e.NATION_CHECK_STATE,e.BORDER_CHECK_STATE,e.IS_MEET_CAR,e.PORT_CHECK_STATE,e.CUSTOM_CHECK_STATE,e.GATE_CHECK_STATE from BUS_CARD_RELEASE e where e.entry_exit_type='101101' "+carno+sdate+" and (e.GATE_CHECK_STATE !='101402' or e.GATE_CHECK_STATE is null) ");
		//获取第offset页，每页共limit条内容，默认查询总数count
		Page p = PageHelper.startPage(pageUtils.getPage(), pageUtils.getRows());
		List<Map<String, Object>> list=sqlAdapterMapper.selectSQL(sql.toString());
		Map dateMap = new HashMap();
	    dateMap.put("total", p.getTotal());
	    dateMap.put("rows", list);
		return dateMap;
	}
	// 进去未出区统计
	public Map getoutsum(CardRelease cardRelease,PageUtils pageUtils,String startdate,String enddate) throws Exception{
		String sdate="";
		String carno="";
		if(startdate!=null&&!startdate.equals("")){
			sdate=sdate+" and entry_time>=to_date('"+startdate+"','yyyy-MM-dd')";
		}
		if(enddate!=null&&!enddate.equals("")){
			sdate=sdate+" and entry_time<=to_date('"+enddate+"','yyyy-MM-dd')+1";
		}
		if(cardRelease.getCarNo()!=null&&!cardRelease.getCarNo().equals("")){
			carno=" and car_no like '%"+cardRelease.getCarNo()+"%'";
		}
		StringBuffer sql =new StringBuffer("select e.car_no,e.entry_time,e.OPERATION_STATE,e.GATE_CHECK_STATE,e.NATION_CHECK_STATE,e.CUSTOM_CHECK_STATE,e.BORDER_CHECK_STATE,e.FINAL_CHECK_STATE from BUS_CARD_RELEASE e where e.entry_exit_type='101102' "+carno+sdate+" and (e.FINAL_CHECK_STATE !='101402' or e.FINAL_CHECK_STATE is null)");
		//获取第offset页，每页共limit条内容，默认查询总数count
		Page p = PageHelper.startPage(pageUtils.getPage(), pageUtils.getRows());
		List<Map<String, Object>> list=sqlAdapterMapper.selectSQL(sql.toString());
		Map dateMap = new HashMap();
	    dateMap.put("total", p.getTotal());
	    dateMap.put("rows", list);
		return dateMap;
	}
	//入境停留车辆人数统计
	public Map getinpersonsum(CardRelease cardRelease,PageUtils pageUtils,String startdate,String enddate) throws Exception{
		String sdate="";
		if(startdate!=null&&!startdate.equals("")){
			sdate=sdate+" and entry_time>=to_date('"+startdate+"','yyyy-MM-dd')";
		}
		if(enddate!=null&&!enddate.equals("")){
			sdate=sdate+" and entry_time<=to_date('"+enddate+"','yyyy-MM-dd')+1";
		}
		StringBuffer sql =new StringBuffer("");
		//获取第offset页，每页共limit条内容，默认查询总数count
		Page p = PageHelper.startPage(pageUtils.getPage(), pageUtils.getRows());
		List<Map<String, Object>> list=sqlAdapterMapper.selectSQL(sql.toString());
		Map dateMap = new HashMap();
	    dateMap.put("total", p.getTotal());
	    dateMap.put("rows", list);
		return dateMap;
	}
	
	//退车统计
	public Map returncarsum(CardRelease cardRelease,PageUtils pageUtils,String startdate,String enddate) throws Exception{
		StringBuffer sql =new StringBuffer("select car_no,count(custom) custom,count(border) border,count(nomeet) nomeet,other "
				+ " from (select e.car_no,decode(custom_check_state,'101403',1,null) custom,"
				+ " decode(border_check_state,'101403',1,null) border,decode(is_meet_car,'101602',1,null) nomeet,"
				+ " (select count(car_no) from BUS_CARD_RELEASE  where final_check_state=101403 or nation_check_state=101403 "
				+ " or port_check_state=101403 or gate_check_state=101403) other from BUS_CARD_RELEASE e where 1=1 ");
		if(startdate!=null&&!startdate.equals("")){
			sql.append(" and entry_time>=to_date('"+startdate+"','yyyy-MM-dd') ");
		}
		if(enddate!=null&&!enddate.equals("")){
			sql.append(" and entry_time<=to_date('"+enddate+"','yyyy-MM-dd') +1");
		}
		if(cardRelease.getCarNo()!=null&&!cardRelease.getCarNo().equals("")){
			sql.append(" and car_no like '%"+cardRelease.getCarNo()+"%' ");
		}
		sql.append(" ) group by car_no,other ");
		//获取第offset页，每页共limit条内容，默认查询总数count
		Page p = PageHelper.startPage(pageUtils.getPage(), pageUtils.getRows());
		List<Map<String, Object>> list=sqlAdapterMapper.selectSQL(sql.toString());
		Map dateMap = new HashMap();
	    dateMap.put("total", p.getTotal());
	    dateMap.put("rows", list);
		return dateMap;
	}
	
}

